package com.kh.pajx.sop.service.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.dao.IClassInfoDao;
import com.kh.pajx.sop.domain.ClassInfo;
import com.kh.pajx.sop.service.IClassInfoService;

@Service
@Transactional
public class ClassInfoServiceImpl implements IClassInfoService {
	
	@Resource
	private IClassInfoDao classInfoDao;

	/**
	 * @see com.kh.pajx.bmp.service.school.IClassInfoService#findClassInfo(java.lang.String)
	 */
	@Override
	public List<ClassInfo> findClassInfo(String graId) {
		return classInfoDao.findClassInfoListByGraId(graId, 1);
	}
	
	/**
	 * @see com.kh.pajx.bmp.service.school.IClassInfoService#getClassInfoMap(java.lang.String)
	 */
	@Override
	public Map<String, String> getClassInfoMap(String graId) {
		Map<String,String> map = new HashMap<String,String>();
		List<ClassInfo> classInfoList = findClassInfo(graId);
		for(ClassInfo cls : classInfoList){
			if(StringUtils.isNotEmpty(cls.getClsShowName())){
				if(cls.getClsName().equals(cls.getClsShowName())){
					map.put(cls.getClsId(), cls.getClsName());
				}else{
					map.put(cls.getClsId(), cls.getClsName()+"("+cls.getClsShowName()+")");
				}
			}else{
				map.put(cls.getClsId(), cls.getClsName());
			}
		}
		return map;
	}
	
	/**
	 * @see com.kh.pajx.bmp.service.school.IClassInfoService#getClassInfoMap(java.lang.String, java.lang.String)
	 */
	@Override
	public Map<String, String> getClassInfoMap(String sclId, String graId) {
		if(StringUtils.isNotEmpty(graId)){
			return getClassInfoMap(graId);
		}
		if(StringUtils.isNotEmpty(sclId)){
			Map<String,String> map = new HashMap<String,String>();
			List<ClassInfo> classInfoList = classInfoDao.findClassInfoListBySclId(sclId, 1);
			for(ClassInfo cls : classInfoList){
				if(StringUtils.isNotEmpty(cls.getClsShowName())){
					if(cls.getClsName().equals(cls.getClsShowName())){
						map.put(cls.getClsId(), cls.getClsName());
					}else{
						map.put(cls.getClsId(), cls.getClsName()+"("+cls.getClsShowName()+")");
					}
				}else{
					map.put(cls.getClsId(), cls.getClsName());
				}
			}
			return map;
		}
		return Collections.emptyMap();
	}

}
